package com.javabase.y2021.m12.day1224;

/**
 * @descriptions: MultiThreadDown
 * @author: Tom
 * @date: 2021/12/24 下午 05:14
 * @version: 1.0
 */
public class MultiThreadDown {
    public static void main(String[] args) throws Exception {
        final DownUtil downUtil = new DownUtil("http://www.wistron.com/ios.png", "ios.png",4);
        // 開始下載
        downUtil.download();
        new Thread(() -> {
            while(downUtil.getCompleteRate() < 1){
                // 每隔一秒查詢一次任務的完成進度
                // GUI程序中可根據進度來繪製進度條
                System.out.println("已完成:" + downUtil.getCompleteRate());
                try{
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        ).start();
    }
}
